home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Dialectic 1.2 / source / Dialectic ƒ / Dialectic code / dialectic scrap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  3.3 KB  |  136 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        dialectic scrap.c
  4.  
  5. Purpose:    This module handles clipboard conversion.
  6.  
  7.  
  8. Dialectic -=- dialect text conversion extraordinare
  9. Copyright ©1994, Mark Pilgrim
  10.  
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program in a file named "GNU General Public License".
  23. If not, write to the Free Software Foundation, 675 Mass Ave,
  24. Cambridge, MA 02139, USA.
  25.  
  26. \**********************************************************************/
  27.  
  28. #include "graphics.h"
  29. #include "dialectic scrap.h"
  30. #include "dialectic.h"
  31. #include "dialectic dispatch.h"
  32. #include "error.h"
  33. #include "progress.h"
  34. #include "program globals.h"
  35. #include "util.h"
  36. #include "environment.h"
  37. #include "menus.h"
  38.  
  39. void NewScrapConvert(void)
  40. {
  41.     int                err;
  42.     Boolean            notDoneYet;
  43.     Str255            titleStr;
  44.     Handle            inputHandle, outputHandle;
  45.     unsigned long    dummy;
  46.     unsigned long    lastSavedOffset;
  47.     
  48.     LoadScrap();
  49.     inputHandle=NewHandle(0L);
  50.     if (GetScrap(inputHandle, 'TEXT', &dummy)==noTypeErr)
  51.     {
  52.         DisposeHandle(inputHandle);
  53.         HandleError(kNoTextInScrap, FALSE);
  54.         return;
  55.     }
  56.     
  57.     gInputLength=GetHandleSize(inputHandle);
  58.     if (gInputLength==0L)
  59.     {
  60.         DisposeHandle(inputHandle);
  61.         HandleError(kScrapTooLarge, FALSE);
  62.         return;
  63.     }
  64.     
  65.     outputHandle=NewHandle(0L);
  66.     
  67.     lastSavedOffset=gInputOffset=gOutputOffset=gAbsoluteOffset=0L;
  68.     
  69.     if ((!gShowProgress) || (gInputLength<=INPUT_BUFFER_MAX))
  70.     {
  71.         gInProgress=TRUE;
  72.         AdjustMenus();
  73.         DrawMenuBar();
  74.     }
  75.     else
  76.     {
  77.         GetItem(gDialectMenu, gWhichDialect+1, titleStr);
  78.         OpenProgressDialog(gInputLength, titleStr);
  79.         SetProgressText("\pConverting clipboard...","\p","\p","\p");
  80.     }
  81.     
  82.     gDoingRTF=gInWord=gSeenI=gSeenBackslash=FALSE;
  83.     gCurlyLevel=0;
  84.     
  85.     notDoneYet=TRUE;
  86.     while ((notDoneYet) && (gAbsoluteOffset<gInputLength))
  87.     {
  88.         if (gInputOffset-lastSavedOffset>INPUT_BUFFER_MAX)
  89.         {
  90.             lastSavedOffset=gInputOffset;
  91.             if ((gShowProgress) && (gInputLength>INPUT_BUFFER_MAX) && (gInProgress))
  92.             {
  93.                 UpdateProgressDialog(gAbsoluteOffset);
  94.                 notDoneYet=DealWithOtherPeople();
  95.             }
  96.         }
  97.         
  98.         if (notDoneYet)
  99.         {
  100.             if (GetHandleSize(outputHandle)-gOutputOffset<OUTPUT_BUFFER_MAX)
  101.                 SetHandleSize(outputHandle, GetHandleSize(outputHandle)+OUTPUT_BUFFER_MAX);
  102.             
  103.             HLock(inputHandle);
  104.             HLock(outputHandle);
  105.             gInputBuffer=*inputHandle;
  106.             gOutputBuffer=*outputHandle;
  107.             
  108.             ConvertDispatch();
  109.             
  110.             HUnlock(inputHandle);
  111.             HUnlock(outputHandle);
  112.         }
  113.     }
  114.     
  115.     if ((gShowProgress) && (gInputLength>INPUT_BUFFER_MAX) && (gInProgress))
  116.     {
  117.         UpdateProgressDialog(gAbsoluteOffset);
  118.         DealWithOtherPeople();
  119.     }
  120.     
  121.     if (notDoneYet)
  122.     {
  123.         ZeroScrap();
  124.         HLock(outputHandle);
  125.         PutScrap(gOutputOffset, 'TEXT', *outputHandle);
  126.     }
  127.     
  128.     DisposeHandle(inputHandle);
  129.     DisposeHandle(outputHandle);
  130.     
  131.     DismissProgressDialog();
  132.     
  133.     if (gTheWindow[kClipboard])
  134.         OpenTheWindow(kClipboard);
  135. }
  136.